//
//  AppDelegate.m
//  AudioVisualFeast
//
//  Created by dllo on 16/1/26.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "AppDelegate.h"
#import <BmobSDK/Bmob.h>
#import "YYT_TheOffcialViewController.h"
#import "YYT_PremiereViewController.h"
#import "YYT_PopularViewController.h"
#import "YYT_SoundYueShowViewController.h"
#import "YYT_FansFocusViewController.h"
#import "YYT_LeftViewController.h"
#import "YYT_DataBaseSingleton.h"

//#import "YYT_LeftViewController.h" // 左侧抽屉

@interface AppDelegate ()

@property (nonatomic, strong)UINavigationController *navigationController;
@property(nonatomic, retain)UITabBarController *tabBC;
@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
    [Bmob registerWithAppKey:@"5167e86addac7899f2aae9f5bd244b68"];
    
    self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
    self.window.backgroundColor = [UIColor blackColor];
    
    YYT_TheOffcialViewController *theOffcial = [[YYT_TheOffcialViewController alloc]init];
    UINavigationController *navigaTh = [[UINavigationController alloc]initWithRootViewController:theOffcial];
    navigaTh.tabBarItem.title = @"官方推荐";
    navigaTh.tabBarItem.image = [[UIImage imageNamed:@"guanfangtuijian"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    navigaTh.tabBarItem.selectedImage = [[UIImage imageNamed:@"guanfangtuijian2"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    YYT_PremiereViewController *premiere = [[YYT_PremiereViewController alloc]init];
    UINavigationController *navigaPr = [[UINavigationController alloc]initWithRootViewController:premiere];
    navigaPr.tabBarItem.title = @"MV首播";
    navigaPr.tabBarItem.image = [[UIImage imageNamed:@"MVshoubo"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    navigaPr.tabBarItem.selectedImage = [[UIImage imageNamed:@"MVshoubo2"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    YYT_PopularViewController *popular = [[YYT_PopularViewController alloc]init];
    UINavigationController *navigaPo = [[UINavigationController alloc]initWithRootViewController:popular];
    navigaPo.tabBarItem.title = @"正在流行";
    navigaPo.tabBarItem.image = [[UIImage imageNamed:@"zhengzailiuxing"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    navigaPo.tabBarItem.selectedImage = [[UIImage imageNamed:@"zhengzailiuxing2"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    YYT_SoundYueShowViewController *soundYueShow = [[YYT_SoundYueShowViewController alloc]init];
    UINavigationController *navigaSo = [[UINavigationController alloc]initWithRootViewController:soundYueShow];
    navigaSo.tabBarItem.title = @"音悦节目";
    navigaSo.tabBarItem.image = [[UIImage imageNamed:@"yinyuejiemu"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    navigaSo.tabBarItem.selectedImage = [[UIImage imageNamed:@"yinyuejiemu2"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    YYT_FansFocusViewController *fansFocus = [[YYT_FansFocusViewController alloc]init];
    UINavigationController *navigaFa = [[UINavigationController alloc]initWithRootViewController:fansFocus];
    navigaFa.tabBarItem.title = @"粉丝聚焦";
    navigaFa.tabBarItem.image = [[UIImage imageNamed:@"fensijujiao"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    navigaFa.tabBarItem.selectedImage = [[UIImage imageNamed:@"fensijujiao2"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    navigaFa.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"粉丝聚焦" image:[UIImage imageNamed:@"fensijujiao"] tag:1005];
    
    
    self.tabBC = [[UITabBarController alloc]init];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeColor:) name:@"changeColor" object:nil];
    
    NSString *red = [[NSUserDefaults standardUserDefaults] objectForKey:@"red"];
    if ([red isEqualToString:@"yes"]) {
        //原色状态
        self.tabBC.tabBar.barTintColor = [UIColor blackColor];
    }else {
        self.tabBC.tabBar.barTintColor = [UIColor darkGrayColor];
    }
    
    
    UINavigationBar *bar = [self.navigationController navigationBar];
    CGFloat navBarHeight = 20.0f;
    CGRect rect = CGRectMake(0, 20, self.window.frame.size.width, navBarHeight);
    [bar setFrame:rect];
    self.tabBC.tabBar.tintColor = [UIColor colorWithRed:48 / 255.0 green:165 / 255.0 blue:136 / 255.0 alpha:1.0];
    self.tabBC.viewControllers = [NSArray arrayWithObjects:navigaTh,navigaPr,navigaPo, navigaSo, navigaFa, nil];
    
    //    右面的抽屉
    LSZLeftViewController *leftViewController = [[LSZLeftViewController alloc]init];
    _drawerViewController = [[YYT_DrawerViewController alloc] init];
    _drawerViewController.rootViewController = self.tabBC;
    _drawerViewController.leftViewController = leftViewController;
    // 右侧展示多少
    _drawerViewController.leftViewShowWidth = 270;
    _drawerViewController.needSwipeShowMenu = true;//默认开启的可滑动展示
    [_drawerViewController showBoundsShadow];
    _window.rootViewController = _drawerViewController;
    [self.window makeKeyAndVisible];
    
    
    YYT_DataBaseSingleton *dataBase = [YYT_DataBaseSingleton shareDataBase];
    [dataBase openDB];
    [dataBase creatTable];
    [dataBase createSeeTable];
//    self.window.rootViewController = self.tabBC;
//    [self.window makeKeyAndVisible];
    return YES;
}

-(void)changeColor:(NSNotification *)notification {
    UIColor *color = [notification object];
    self.tabBC.tabBar.barTintColor = color;
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
